﻿//-----------------------------------------------------------------------
// <copyright file="LoginController.cs" company="Simnova LLC">
//     Copyright (c) Simnova LLC. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Simnova.Collaborate.ASPMVC.Controllers
{
    using System;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Script.Serialization;

    public class LoginController : Controller
    {
        public void Index()
        {
            RenderView("Login");
        }

        public void Authenticate(string email, string password)
        {
            AppServer.CollaborateServiceClient csc = new Simnova.Collaborate.ASPMVC.AppServer.CollaborateServiceClient();
            AppServer.User user = csc.GetUser(email, password);
            string authenticationStatus = "fail";
            if (user != null)
            {
                HttpContext.Session["user"] = user;
                authenticationStatus = "pass";
            }

            JavaScriptSerializer jss = new JavaScriptSerializer();
            HttpContext.Response.Write(jss.Serialize(authenticationStatus));

            ////RenderView("Index",HttpContext.Session["user"]);
        }

        protected override void OnActionExecuting(FilterExecutingContext filterContext)
        {
            // Do something.
        }

        protected override void OnActionExecuted(FilterExecutedContext filterContext)
        {
            // Do something.
        }
    }
}
